package cn.itcast;

import java.util.ArrayList;
import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;

@SpringBootApplication
@Configuration
public class SpringBoot  extends WebMvcConfigurerAdapter  {
	 @Override
	 public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
	 	super.configureMessageConverters(converters);
	 	//1.定义一个convert转换消息的对象
	 	FastJsonHttpMessageConverter fastConverter=new FastJsonHttpMessageConverter();
	 	//2.添加fastjson的配置信息 例如:是否格式化返回的json数据
	 	FastJsonConfig fastJsonConfig=new FastJsonConfig();
	 	fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
	 	//3.在convert中添加配置信息
	 	//处理中文乱码问题
        List<MediaType> fastMediaTypes = new ArrayList<>();
        fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
        fastConverter.setSupportedMediaTypes(fastMediaTypes);
        fastConverter.setFastJsonConfig(fastJsonConfig);
	 	//4.讲convert添加到converts中
	 	converters.add(fastConverter);
	 	
	 }
    
	public static void main(String[] args) {
	
//程序入口,运行项目,启动main函数
		//springboot项目的启动方法
		SpringApplication.run(SpringBoot.class, args);
		
	}

}
